package engine;

import java.util.ArrayList;

/**
 * 
 * Main class for the entire engine.
 * All engine functionality should be built off of here.
 * This part of the code should be entirely encapsulated.
 * 
 * @author Dylan Swiggett
 *
 */
public class APOPS {
	public int ips;	//Iterations per second -- higher value means more accurate physics
	private ArrayList<PhysicsObject> objects;	//All physics objects in the scene
	public double time;
	//TODO: RTree for storing all physics objects.
	
	public APOPS(){
		objects = new ArrayList<PhysicsObject>();
		time = 0;
		ips = 30;
		
		objects.add(new Circle(100, 100, 20));
		objects.add(new Circle(100, 200, 100));
	}
	
	/**
	 * 
	 * Run the specified number of iterations in the physics engine.
	 * Passing ips to iterate() will run one second of physics.
	 * 
	 * @param iterations
	 */
	public void iterate(int iterations){
		double timestep = iterations / ips;
		for (int i = 0; i < iterations; i++){
			time += timestep;
			/*
			 * MAIN ITERATION
			 */
			// Check intersection
			for (PhysicsObject obj1 : objects){
				for (PhysicsObject obj2 : objects){
					if (obj1.equals(obj2)) continue;
					
					obj1.collideWithPhysicsObject(obj2);
				}
			}
		}
	}
}
